Repository navigation
Report native histograms to M3 as sketches - #288
Open
adamjeanlaurent wants to merge 2 commits into
Open
adamjeanlaurent wants to merge 2 commits into
adamjeanlaurent wants to merge 2 commits into
Conversation
tally v7 has native histograms, but the default accumulator could not marshal them, and the M3 reporter dropped every payload. m3collector now accepts native histograms as SKETCH metrics. This change makes tally send them. The default accumulator is now an OpenTelemetry base-2 exponential histogram from the upstream pkg/expohisto module. It marshals to the proto3 ExponentialHistogram message that m3collector decodes. The accumulator drops NaN and infinities, limits the bucket count to 160, and refuses a scale below -4, because m3collector rejects those payloads. The M3 thrift schema gets MetricType SKETCH = 4 and the optional MetricValue field 5: binary sketch. The reporter sends each payload as a SKETCH metric and computes its size on each report. It drops a payload that does not fit in one packet and counts it in tally.internal.num-native-histograms-dropped. The upstream module requires Go 1.26, so the go line moves from 1.20 to 1.26. This also needs a newer staticcheck and a fix to format verbs in a vendored thrift test that vet now rejects. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tally v7 has native histograms, but the default accumulator could not marshal them, and the M3 reporter dropped every payload. m3collector now accepts native histograms as
SKETCHmetrics. This PR makes tally send them.Changes
native_histogram_expohisto.go(new): the defaultNativeHistogramData. It wraps the upstream OpenTelemetrypkg/expohistohistogram (structure.Float64).MarshalBinarywrites the proto3ExponentialHistogrammessage that m3collector decodes, withgoogle.golang.org/protobuf/encoding/protowire. No generated code is needed.scope.go,native_histogram.go,types.go: a scope withoutNativeHistogramFactorynow uses this accumulator.ScopeOptions.NativeHistogramFactorystill overrides it.ErrNativeHistogramBackendNotConfiguredstays exported because v7.0.0 has it, but it is deprecated, because nothing returns it now.m3/thrift/v2/v2.thrift: addSKETCH = 4toMetricTypeand5: optional binary sketchtoMetricValue. This is the same schema as m3collector.m3/thrift/v2/ttypes.go: add the new enum value and field. The Thrift 0.9.3 compiler was not available, so I edited the file by hand to match the 0.9.3 generator output for an optionalbinaryfield.m3/thrift/thrift.diff: rebuilt from a real pre-image, somake gen-thriftstill applies cleanly. Only the index hashes and the hunk offsets change.m3/reporter.go:AllocateNativeHistogramallocates aSKETCHmetric.ReportNativeHistogramsets the payload and computes the size on each report, because the payload size changes from one interval to the next. A payload that does not fit in one packet is dropped and counted intally.internal.num-native-histograms-dropped.flush()clears the payloads, so the reused slice does not keep them alive.version.go:Versiongoes from7.0.0to7.1.0. The reporter sends it as theversiontag on internal metrics. Tag the merge commit asv7.1.0.Go version
The upstream
pkg/expohistomodule requires Go 1.26, so thegoline moves from 1.20 to 1.26.0. This also needs these changes:tools/go.mod: staticcheck v0.3.2 to v0.8.2. The old version cannot read Go 1.26.thirdparty/.../thrift/protocol_test.go: on Go 1.26, vet rejects%qwith integer arguments. Ten format verbs change to%v. This is a test-only change.Compatibility
SKETCHmetrics by default. A collector without sketch support, or in strict mode, can reject the whole batch, which also loses the counters and gauges in it. All m3collector deployments must support sketches before services upgrade.Testing
make test(with-race) andmake coverpass.TestExpoHistogramDataGoldenBytescompares the payload with bytes worked out by hand from the proto3 rules.TestExpoHistogramDataMixedValuesuses the same input as the m3collectorTestSketchPayloadRoundTrip. It decodes the payload independently of the encoder and checks scale, counts, sum, min, max, bucket offsets, and that the count equals the zero count plus the bucket counts.Clear.TestMetricValueSketchRoundTripwrites and reads the new field, set and unset, for binary and compact protocol.TestReporterNativeHistogramandTestScopeNativeHistogramcheck that the fake M3 server receivesSKETCHmetrics with the exact payload.TestReporterNativeHistogramTooLargeIsDroppedchecks the drop and the drop counter.TestBatchSizesnow mixes in sketch payloads of random size, and every packet stays under the size limit.Known issues not fixed here
io/ioutil,atomic.Bool.CAS,rand.Seed).if: matrix.latest, and the matrix has nolatestkey.🤖 Generated with Claude Code